home *** CD-ROM | disk | FTP | other *** search
/ PC Shareware 1997 February / PC Shareware 1997-02.iso / programy / e! / api / toglcase.c_ / toglcase.C
Encoding:
C/C++ Source or Header  |  1995-03-05  |  1.9 KB  |  64 lines

  1. /*------------------------------------------------
  2.    TOGLCASE.C -- Extension DLL for E! - version 2.0
  3.  
  4.    To compile: nmake /f toglcase.mak
  5.  
  6.    Once compiled, copy TOGLCASE.EWD to your USER directory.
  7.  
  8.    TOGLCASE can be used to toggle the case of each character of the current
  9.    word. For example, bADcASE would be converted to BadCase. Since we use
  10.    EWSetLineAt() and a line buffer to change the line instead of directly
  11.    modifying the original line, this action can be undone.
  12.  
  13.    To use this DLL simply load it from the user menu or add its name to the
  14.    list of autoloaded Extension DLLs by using the Autoload dialog box from
  15.    the User Menu of EW. That's all.
  16.  
  17.    This Extension DLL uses no hook. It merely uses some API functions to
  18.    select the word at the cursor position.
  19.  
  20.    You can assign this extension to a keystroke. See the documentation for
  21.    a description of how to assign DLL execution to a keystroke.
  22.   ------------------------------------------------*/
  23.  
  24. #include <windows.h>
  25. #include "ewapi2.h"
  26.  
  27. int FAR PASCAL LibMain (HANDLE hInstance, WORD wDataSeg, WORD wHeapSize,
  28.             LPSTR lpszCmdLine)
  29. {
  30.   if (wHeapSize > 0)
  31.     UnlockData (0) ;
  32.   return 1 ;
  33. }
  34.  
  35. char far LineBuffer[256];
  36.  
  37. int FAR PASCAL EWExecute(unsigned int RoutineId)
  38. {
  39.   long    WordBoundaries;
  40.   long    CurrentLine;
  41.   int    i;
  42.  
  43.   /* Get the first and last character of the current word */
  44.   WordBoundaries = EWGetCurWord();
  45.   if (WordBoundaries != -1L) {
  46.     /* Get the current line */
  47.     CurrentLine = EWGetCaretPosY();
  48.     /* Change case of each character */
  49.     lstrcpy(LineBuffer, EWGetLineAt(CurrentLine));
  50.     for (i = (int) LOWORD(WordBoundaries); i < (int) HIWORD(WordBoundaries); i++)
  51.     {
  52.       if (IsCharUpper(LineBuffer[i]))
  53.     AnsiLowerBuff(LineBuffer + i, 1);
  54.       else
  55.     AnsiUpperBuff(LineBuffer + i, 1);
  56.     }
  57.     EWSetLineAt(LineBuffer, CurrentLine);
  58.     EWSetModified();
  59.     return(0);
  60.   }
  61.   else
  62.     return(ewerr_EXTFAILED);
  63. }
  64.